package main

import "fmt"

func main() {
	testSlice()
	testArray()
}

func testSlice() {
	fmt.Println("-------------testSlice-------------")
	var stuArray []Student = make([]Student, 2)

	var stu1 Student = Student{"张三", 18, "重庆"}
	var stu2 Student = Student{Name: "李四", Age: 20, Addr: "北京"}
	var stu3 *Student = &Student{Name: "李四", Age: 20, Addr: "北京"}
	fmt.Println(stu3)  //&{李四 20 北京}
	fmt.Println(*stu3) //{李四 20 北京}
	stuArray[0] = stu1
	stuArray[1] = stu2
	stuArray = append(stuArray, *stu3)
	//stuArray = append(stuArray, stu3) //Cannot use 'stu3' (type *Student) as the type Student
	fmt.Println(stuArray)
}

func testArray() {
	fmt.Println("-------------testArray-------------")
	var stuArray [3]*Student
	stuArray[0] = &Student{Name: "张三", Age: 18, Addr: "重庆"}
	stuArray[1] = &Student{Name: "李四", Age: 20, Addr: "北京"}
	stuArray[2] = &Student{Name: "李四", Age: 20, Addr: "北京"}
	fmt.Println(stuArray) //[0xc00001e270 0xc00001e2a0 0xc00001e2d0]
	for i := range stuArray {
		fmt.Println(*stuArray[i])
		//{张三 18 重庆}
		//{李四 20 北京}
		//{李四 20 北京}
	}

}

type Student struct {
	Name string
	Age  int
	Addr string
}
